﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;
using Microsoft.SharePoint;
using ProjectHT.YKDGVB2012.Core.Datacontract;
using Telerik.Web.UI;

namespace ProjectHT.YKDGVB2012.Core.UserControls
{
    public class EditComment : System.Web.UI.UserControl
    {

        protected RadTextBox txtFullname;
        protected RadTextBox txtEmail;
        protected RadTextBox txtphonenumber;
        protected RadTextBox txtFaxnumber;
        protected RadTextBox RadTextBox;
        protected RadTextBox txtContent;
        protected RadTextBox txtaddress;
        protected RadButton _raddvSave;

        protected RadTextBox txtTitle;
        protected Label Titledt;
        protected Label description;
        protected Label viewcomment;
        protected CheckBox btnstats;
        private IComment _comment;
        public EditComment()
        {
            var services = new CommentServices(SPContext.Current);
            _comment = services;

        }

        protected override void OnInit(EventArgs e)
        {
            _raddvSave.Click += new EventHandler(_raddvSave_Click);
        }

        protected void _raddvSave_Click(object sender, EventArgs e)
        {

            var ids = String.Format("{0}", Context.Request.Params[Helper.Constans.ITEMID]);
            if (!String.IsNullOrEmpty(ids))
            {
                var comment = _comment.GetItemById(Convert.ToInt32(ids));
                comment.Title = txtTitle.Text;
                comment.Address = txtaddress.Text;
                comment.Email = txtEmail.Text;
                comment.Fax = txtFaxnumber.Text;
                comment.FullName = txtFullname.Text;
                comment.PhoneNumber = txtphonenumber.Text;
                comment.Contents = txtContent.Text;
                comment.Statust = btnstats.Checked;
                _comment.Update(comment);
            }
            this.Page.ClientScript.RegisterStartupScript(this.GetType(), "pageLoad", "Message.alert(\"Dữ liệu đã được câp nhật\", function () { CloseWindow();}, \"\");",
                                                    true);

        }

        protected void Page_Load(object sender, EventArgs e)
        {
            var ids = String.Format("{0}", Context.Request.Params[Helper.Constans.ITEMID]);
            if (!IsPostBack)
            {
                if (!String.IsNullOrEmpty(ids))
                {
                    var comment = _comment.GetItemById(Convert.ToInt32(ids));
                    txtTitle.Text = comment.Title;
                    txtaddress.Text = comment.Address;
                    txtEmail.Text = comment.Email;
                    txtFaxnumber.Text = comment.Fax;
                    txtFullname.Text = comment.FullName;
                    txtphonenumber.Text = comment.PhoneNumber;
                    txtContent.Text = comment.Contents;
                    if (comment.Statust != null) btnstats.Checked = (bool)comment.Statust;
                }
            }
        }



    }
}
